#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <cstdlib>
#include <cstdio>

using namespace std;


void bfs(vector< vector<char> >& g, int x, int y)
{
    queue< pair<int, int> > q;
    q.push(make_pair(x, y));
    g[x][y] = '.';
    while (!q.empty())
    {
        int xt = q.front().first;
        int yt = q.front().second;
        q.pop();
        if (xt > 0 && g[xt - 1][yt] != '.')
        {
            g[xt - 1][yt] = '.';
            q.push(make_pair(xt-1, yt));
        }
        if (xt < g.size() - 1 && g[xt + 1][yt] != '.')
        {
            g[xt + 1][yt] = '.';
            q.push(make_pair(xt + 1, yt));
        }
        if (yt > 0 && g[xt][yt - 1] != '.')
        {
            g[xt][yt - 1] = '.';
            q.push(make_pair(xt, yt - 1));
        }
        if (yt < g.size() - 1 && g[xt][yt + 1] != '.')
        {
            g[xt][yt + 1] = '.';
            q.push(make_pair(xt, yt + 1));
        }
    }
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int n;
    cin>>n;
    vector< vector< char > > a(n);
    for (int i = 0; i<n; ++i)
    {
        for (int j = 0; j<n ;++j)
        a[i].push_back(' ');
    }
    int x,y;
    while (cin>>x>>y)
    {
        a[x][y] = '.';
    }
    int res = 0;
    for (int i =0 ; i<n; ++i)
    {
        for (int j = 0; j<n; ++j)
        {
            if (a[i][j] == ' ')
            {
                bfs(a, i, j);
                ++res;
            }
        }
    }
    cout<<res;
    return 0;
}
